package chapter4;


import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;

public class ButtonKeyEvent1 extends ApplicationWindow{

	public ButtonKeyEvent1() {
		super(null);
	}

	@Override
	protected Control createContents(Composite parent) {
		Button button = new Button(parent, SWT.CENTER);

		button.setText("luik");
		
		button.addKeyListener( new KeyAdapter(){
			@Override
			public void keyPressed(KeyEvent e) {
				String s = "";
				
				if ((e.stateMask & SWT.ALT) != 0) {
					s += "ALT - ";
				}

				if ((e.stateMask & SWT.CTRL) != 0) {
					s += "CTRL - ";
				}
				if ((e.stateMask & SWT.SHIFT) != 0) {
					s += "SHIFT - ";
				}

				switch (e.keyCode) {
				case SWT.BS:
					s += "backspace";
					break;
				case SWT.DEL:
					s += "delete";
					break;	
				default:
					s +=  "" + e.character;
				break;
				}

				System.out.println(s);
			}

		});

		return super.createContents(parent);
	}

	public static void main(String[] args) {
		ButtonKeyEvent1 be1 = new ButtonKeyEvent1();
		be1.setBlockOnOpen(true);
		be1.open();

		Display.getCurrent().dispose();
	}
}
